/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package FiveInARow;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 *
 * @author houfukude
 */
public class FiveInARow implements MouseListener,ActionListener{
    JFrame frame = new JFrame("Five In A Row");
    JTextField tf1,tf2;
    JButton b;
    JLabel time = new JLabel("60:00");
    JMenuBar jmb;
    JMenu jm1;
    JMenuItem jmi1;
    int BoW = 1;
    public static void main(String args[]) {
        FiveInARow fiar = new FiveInARow();
        try{
            fiar.JMBar();
            fiar.start();
            
        }
        catch (Exception e) {

        }
            
            
        
        
    }


    public void JMBar() throws Exception{
        //menubar
        jmb = new JMenuBar();
        frame.setJMenuBar(jmb);

        //file
        jm1 = new JMenu("File(F)");
        jm1.setMnemonic(KeyEvent.VK_F);
        jmb.add(jm1);
        //file menu
        jmi1 = new JMenuItem("Start(S)");
        jmi1.setMnemonic(KeyEvent.VK_S);
        jmi1.setActionCommand("Start");
        jmi1.addActionListener(this);
        jm1.add(jmi1);

        jmi1 = new JMenuItem("Cancel(C)");
        jmi1.setMnemonic(KeyEvent.VK_C);
        jmi1.setActionCommand("Cancel");
        jmi1.addActionListener(this);
        jm1.add(jmi1);

        jm1.add(new JSeparator());

        jmi1 = new JMenuItem("Exit(E)");
        jmi1.setMnemonic(KeyEvent.VK_E);
        jmi1.setActionCommand("Exit");
        jmi1.addActionListener(this);
        jm1.add(jmi1);

        //Option
        jm1 = new JMenu("Option(O)");
        jm1.setMnemonic(KeyEvent.VK_O);
        jmb.add(jm1);
        //color menu
        jmi1 = new JMenuItem("Color");
        jmi1.setActionCommand("Color");
        jmi1.addActionListener(this);
        jm1.add(jmi1);
        //切换到日期计算
        jmi1 = new JMenuItem("日期计算");
        jmi1.setActionCommand("date");
        jmi1.addActionListener(this);
        jm1.add(jmi1);


        //Help
        jm1 = new JMenu("Help");
        jm1.setMnemonic(KeyEvent.VK_H);
        jmb.add(jm1);
        //option menu
        jmi1 = new JMenuItem("Help website");
        jmi1.setActionCommand("Help");
        jmi1.addActionListener(this);
        jm1.add(jmi1);

        //about
        jm1 = new JMenu("About");
        jm1.setMnemonic(KeyEvent.VK_A);
        jmb.add(jm1);
        //option menu
        jmi1 = new JMenuItem("About the author");
        jmi1.setActionCommand("About");
        jmi1.addActionListener(this);
        jm1.add(jmi1);

    }

    private void start() {

        b = new JButton("Restart");
        b.addActionListener(this);
        tf1 = new JTextField("by 彭福德",15);
        tf2 = new JTextField("初始化完成！",15);
        MyJPanel Panel = new MyJPanel();
        Panel.addMouseListener(this);
        Container allCP = frame.getContentPane();
        allCP.setBackground(Color.pink);
        allCP.setLayout (null);

        tf1.setHorizontalAlignment (JTextField.CENTER);
        tf1.setEditable(false);
        tf2.setHorizontalAlignment (JTextField.CENTER);
        tf2.setEditable(false);
        allCP.add(b);
        b.setBounds(10, 10, 100, 30);
        allCP.add(tf2);
        tf2.setBounds(110, 10, 100, 30);
        allCP.add(time);
        time.setBounds(240, 10, 100, 30);
        allCP.add(tf1);
        tf1.setBounds(310, 10, 100, 30);
        allCP.add(Panel);
        Panel.setBounds(0,30,440,440);
        frame.setResizable(false);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(440, 500);
        frame.setVisible(true);
        System.out.println("OK");

    }
    public void actionPerformed(ActionEvent e) {
        try{
            JButton button = (JButton)e.getSource();
            if(button == b){
            System.out.println("button ok");
            tf1.setText("");
            tf2.setText("");
            }
        }catch(Exception ex){
            Item(e);

        }
    }

    void Item(ActionEvent e){

        if(e.getActionCommand().equals("Start")){

        }
        if(e.getActionCommand().equals("Cancel")){

        }
        if(e.getActionCommand().equals("Help")){

        }
        if(e.getActionCommand().equals("Color")){

        }
        if(e.getActionCommand().equals("date")){
           
        }
        if(e.getActionCommand().equals("About")){

            JOptionPane.showMessageDialog(frame,
                        "welcome to use the Calculator! \n"+
                        "our bbs is http: \n"+
                         "Powered by houfukude",
                        "welcome",
                        JOptionPane.INFORMATION_MESSAGE);
        }
        if(e.getActionCommand().equals("Exit")){

            System.exit(0);
        }

    }

    public void mouseClicked(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mousePressed(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
        
    }

    public void mouseReleased(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseEntered(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseExited(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    
    
    
}
